import execjs

# 1. 定义js代码
js_code = """
function hello() {
    console.log("hello")
    return "hello"
}
"""
# 2. 编译js代码
code_compiled = execjs.compile(js_code)
# 3. 调用js代码  call / eval
print(code_compiled.call("hello"))


js_code_2 = """
function sum(num1,num2) {
    return num1+num2
}
"""
code_compiled_2 = execjs.compile(js_code_2)
print(code_compiled_2.call("sum", 1, 2))
print(code_compiled_2.eval("sum(1,2)"))
